/*
  Part of the MasterTool3D project - http://code.google.com/p/master-tool-3d

  Copyright (c) 2011 Ingo Pueschl

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation, version 2.1.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General
  Public License along with this library; if not, write to the
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  Boston, MA  02111-1307  USA
*/

package techjit.gfx.core;

import java.util.ArrayList;

import techjit.util.LogManager;

public abstract class GFX_Layout extends GFX_SceneElement {

	// ENUMS
	public enum AlignmentEnum {
		ADJACENT, CENTER, REMOTE
	}

	// FIELDS
	protected AlignmentEnum alignmentY = AlignmentEnum.ADJACENT;
	protected AlignmentEnum alignmentZ = AlignmentEnum.ADJACENT;

	protected ArrayList<GFX_SceneElement> elements = new ArrayList<GFX_SceneElement>();;

	// CONSTRUCTORS
	public GFX_Layout(GFX_Scene rootScene) {
		// header
		super(rootScene);
	}

	// METHODS
	public void add(GFX_SceneElement element) {
		elements.add(element);
		element.changeParent(this);
		// tail
		logAddElementsResult();
	}

	public void changeAlignmentY(AlignmentEnum alignmentY) {
		this.alignmentY = alignmentY;
	}

	public void changeAlignmentZ(AlignmentEnum alignmentZ) {
		this.alignmentZ = alignmentZ;
	}

	protected boolean hasChildElements() {
		if (elements != null && !elements.isEmpty()) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public void log() {
		LogManager.logALL("<GFX_Layout>");
		LogManager.indent();
		{
			LogManager.logALL("elements = " + elements);
			super.log();
		}
		LogManager.deindent();
	}

	protected GFX_SceneElement navi_getFirstChild() {
		if (hasChildElements()) {
			return elements.get(0);
		} else {
			return null;
		}
	}

	protected GFX_SceneElement navi_getLastChild() {
		if (hasChildElements()) {
			return elements.get(elements.size() - 1);
		} else {
			return null;
		}
	}

	protected GFX_SceneElement navi_getNextChild(GFX_SceneElement child) {
		int index = elements.indexOf(child);
		int lastIndex = elements.size() - 1;
		if (index == lastIndex) {
			return child;
		} else {
			return elements.get(index + 1);
		}
	}

	protected GFX_SceneElement navi_getPreviousChild(GFX_SceneElement child) {
		int index = elements.indexOf(child);
		if (index == 0) {
			return child;
		} else {
			return elements.get(index - 1);
		}
	}

}
